<?php

/**
 * This is the model class for table "tbl_access_right".
 *
 * The followings are the available columns in table 'tbl_access_right':
 * @property integer $id
 * @property integer $read
 * @property integer $write
 * @property string $pages_read
 * @property string $pages_write
 * @property string $group
 *
 * The followings are the available model relations:
 * @property TblUser[] $tblUsers
 */
class AccessRight extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return AccessRight the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_access_right';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('read, write', 'numerical', 'integerOnly'=>true),
			array('group', 'length', 'max'=>255),
			array('pages_read, pages_write', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, read, write, pages_read, pages_write, group', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tblUsers' => array(self::HAS_MANY, 'TblUser', 'tbl_access_right_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'read' => 'Read',
			'write' => 'Write',
			'pages_read' => 'Pages Read',
			'pages_write' => 'Pages Write',
			'group' => 'Group',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('read',$this->read);
		$criteria->compare('write',$this->write);
		$criteria->compare('pages_read',$this->pages_read,true);
		$criteria->compare('pages_write',$this->pages_write,true);
		$criteria->compare('group',$this->group,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}